import { formatDataToUrl } from '../util/common';

export default function (url, data, method) {
  if(method === 'get') {
    url = formatDataToUrl(url, data)
    if (window.fetch) {
      window.fetch(url, {
        method: "HEAD",
        mode: "no-cors"
      }).catch(() => {});
      return;
    }
    const img = new Image();
    img.onerror = img.onload = () => {};
    img.src = url;
  }else  if(method === 'post') {
    const oReq = new XMLHttpRequest();
    oReq.open("post", url, true)
    oReq.setRequestHeader('Content-type', 'application/json')
    oReq.onreadystatechange = function () {}
    oReq.send(JSON.stringify(data))
  }
}